<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ include file="../include.jsp"%>
<style>
.site-block {
	padding: 20px;
	border: 1px solid #eee;
}

.site-text {
	position: relative;
}
</style>
<div class="site-block site-text">
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">公告标题</label>
			<div class="layui-input-block">
				<input type="text" name="noticeTitle" lay-verify="required" placeholder="请输入公告标题" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">发布时间</label>
			<div class="layui-input-block">
				<input type="text" name="publishTime" lay-verify="required" placeholder="请选择发布时间" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
			</div>
		</div>

		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">公告简述</label>
			<div class="layui-input-block">
				<textarea name="explain" lay-verify="required" placeholder="请输入公告简述" class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">公告详情</label>
			<div class="layui-input-block">
				<textarea name="content" id="${moduleName }-${moduleAction }-content" class="layui-textarea layui-hide" lay-verify="content" placeholder="请输入公告详情" class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">发布者</label>
			<div class="layui-input-block">
				<input type="text" name="publisher" lay-verify="required" placeholder="请输入发布者姓名" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="${moduleName }-${moduleAction }">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary" id="${moduleName }-${moduleAction }-reset">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
	layui.use(['form','laydate','layedit'], function() {
		var form = layui.form(),
		$ = layui.jquery,
		layedit = layui.layedit;
		
		form.render();
		
		  //自定义工具栏
		 var indexNotice = layedit.build('${moduleName }-${moduleAction }-content', {
		    tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
		    ,height: 100
		  });
		
		
		//自定义验证规则
		  form.verify({
			  name: function(value){
			      if(value.length < 4){
			        return '学生姓名至少得4个字符啊';
			      }
			  }
		  	  ,content: function(value){
			      layedit.sync(indexNotice);
			  }
		    
		  });
		//监听提交
		form.on('submit(${moduleName }-${moduleAction })', function(data) {
		//	layer.msg(JSON.stringify(data.field));
			var tmpIndex = layer.load({shade: [0.8, '#393D49']});
		    $.post('${ctx}/teacher/${moduleName }/${moduleAction}',data.field,function(rst){
		    	console.debug(rst);
		    	layer.close(tmpIndex);
		    	if(!rst){
		    		layer.msg('网络连接错误，请稍后再试。。。', {
		    			icon: 2,
		    			shade: [0.8, '#393D49'],
	    			  	anim: 6
	    			});
		    		return ;
		    	}
		    	
		    	if('error' == rst.code){
		    		layer.msg(rst.message, {
		    			time:2000,
		    			icon: 2,
		    			shade: [0.8, '#393D49'],
	    			  	anim: 6
	    			});
		    		return ;
		    	}
		    	layer.confirm('新增成功,留在本页继续添加?',{icon: 3, title:'提示'}
		    	, function(index){
		    		layer.close(index);
		    		$('#${moduleName }-${moduleAction }-reset').trigger('click') ;
		    	}
		    	, function(index){
		    		layer.closeAll();
		    		$('#${moduleName }SearchBtn').trigger('click') ;
		    	});       
		    	
		    },'json');
		
			return false;
		});
	});
</script>